package Magnitudes;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Test;

public class PesosTest extends TestCase {

	Pesos pesosToTest = new Pesos(100);
	Pesos pesosToTestWithCents = new Pesos(100.50);
	Percentage percentageMock = mock(Percentage.class);

	@Before
	public void setUp() {
		when(percentageMock.amount()).thenReturn((double) 10.0);
	}

	@Test
	public void testGivenPesosWithAmountWhenIsComparedWithAnotherPesosWithAmountShouldReturnIsEquals() {
		Pesos anotherPesos = new Pesos(100);
		assertTrue(pesosToTest.equals(anotherPesos));
	}

	@Test
	public void testGivenAPesosWhithAmount100WhenToStringIsCalledShouldReturnAStringPesos100() {

		String stringReturned = pesosToTest.toString();
		assertEquals("$100,00", stringReturned);
	}

	@Test
	public void testGivenAPesosWhithAmmount100and50CentsWhenToStringIsCalledShouldReturnAStringPesos100and50() {

		String stringReturned = pesosToTestWithCents.toString();

		assertEquals("$100,50", stringReturned);
	}

	@Test
	public void testGivenAPesosWithAmmount100WhenAmmountIsCalledShouldReturn100float() {

		double amountReturned = pesosToTest.amount();
		assertEquals(100.00, amountReturned);

	}

	@Test
	public void testGivenAPesosWithAmmount100and50centsWhenAmmountIsCalledShouldReturn100and50float() {

		double amountReturned = pesosToTestWithCents.amount();

		assertEquals(100.50, amountReturned);

	}

	@Test
	public void testGivenAPesosWhenIAddTheSameShouldReturnPesosWithDoubleAmount() {

		Pesos amountUnderTest = pesosToTest.add(pesosToTest);
		Pesos doublePesos = new Pesos(200);
		Pesos amountUnderTestWithCents = pesosToTestWithCents
				.add(pesosToTestWithCents);
		Pesos doublePesosWithCents = new Pesos(201);

		assertTrue(doublePesos.equals(amountUnderTest));
		assertTrue(doublePesosWithCents.equals(amountUnderTestWithCents));
	}

	@Test
	public void testGivenAPesos100WhenIAddPesos100and50ShouldReturnPesos200and50() {

		Pesos amountUnderTest = pesosToTest.add(pesosToTestWithCents);
		Pesos doublePesos = new Pesos(200.50);

		assertTrue(doublePesos.equals(amountUnderTest));
	}

	@Test
	public void testGivenAPesosWhenISubTheSameShouldReturnPesos0Amount() {

		Pesos zeroPesos = new Pesos(0);
		Pesos amountUnderTest = pesosToTest.sub(pesosToTest);
		assertEquals(zeroPesos.amount(), amountUnderTest.amount());
		amountUnderTest = pesosToTestWithCents.sub(pesosToTestWithCents);
		assertTrue(zeroPesos.equals(amountUnderTest));

	}

	@Test
	public void testGivenAPesos100WhenSubPercentage10ShouldReturnPesos90() {

		Pesos pesosNinety = new Pesos(90);
		Pesos amountUnderTest = pesosToTest.subPercentage(percentageMock);

		assertTrue(pesosNinety.equals(amountUnderTest));
	}

	@Test
	public void testGivenAPesos100WhenAddPercentage10ShouldReturnPesos110() {

		Pesos pesosOneHundredAndTen = new Pesos(110);
		Pesos amountUnderTest = pesosToTest.addPercentage(percentageMock);

		assertTrue(pesosOneHundredAndTen.equals(amountUnderTest));
	}

	@Test
	public void testGivenAPesos100WhenDivBy50ShouldReturnPesos2() {
		Pesos returnValue = pesosToTest.div(50.00);
		Pesos two = new Pesos(2);
		assertTrue(two.equals(returnValue));
	}
}
